#include <stdio.h>
#include <iostream>

#include "world3.h"

world3::world3(void)
{
	self = this;
	int i,j;
	for(j = 0; j < MAP_SIZE_HEIGHT ; j ++)
	{
		map[0][j] = new note();
		map[0][j]->getSprite()->setPosition(ccp(0*40+20,j*40+20));
		this->addChild(map[0][j]->getSprite(),0);
		map[0][j]->setnote(0,j,wall);

		map[MAP_SIZE_WIDTH - 1][j] = new note();
		map[MAP_SIZE_WIDTH - 1][j]->getSprite()->setPosition(ccp((MAP_SIZE_WIDTH - 1)*40+20,j*40+20));
		this->addChild(map[MAP_SIZE_WIDTH - 1][j]->getSprite(),0);
		map[MAP_SIZE_WIDTH - 1][j]->setnote(MAP_SIZE_WIDTH - 1,j,wall);

	}
	for(i = 1; i < MAP_SIZE_WIDTH - 1 ; i ++)
	{
		map[i][0] = new note();
		map[i][0]->getSprite()->setPosition(ccp(i*40+20,0*40+20));
		this->addChild(map[i][0]->getSprite(),0);
		map[i][0]->setnote(i,0,wall);

		map[i][MAP_SIZE_HEIGHT - 1] = new note();
		map[i][MAP_SIZE_HEIGHT - 1]->getSprite()->setPosition(ccp(i*40+20,(MAP_SIZE_HEIGHT - 1)*40+20));
		this->addChild(map[i][MAP_SIZE_HEIGHT - 1]->getSprite(),0);
		map[i][MAP_SIZE_HEIGHT - 1]->setnote(i,MAP_SIZE_HEIGHT - 1,wall);

		//for(j = 1; j < MAP_SIZE_HEIGHT - 1; j ++)
		//{
		//	
		//	map[i][j] = new note();
		//	map[i][j]->getSprite()->setPosition(ccp(i*40+20,j*40+20));
		//	this->addChild(map[i][j]->getSprite(),0);
		//	if(i == 5 && j==5)
		//		map[i][j]->setnote(i,j,stones);
		//	else
		//		map[i][j]->setnote(i,j,blank);
		//}
	}
	srand((int)time(NULL));
	for(int k = 0; k < 10; k ++)
	{
		do
		{
			i = rand()%(MAP_SIZE_WIDTH-2) + 1;
			j = rand()%(MAP_SIZE_HEIGHT-2) + 1;
		} while (map[i][j]->gettype() != blank || i < 3 || j <3 || j > 8);
		map[i][j]->settype(stones);
	}
}

world3::~world3(void)
{
	delete sk;
	delete supersk;
	delete fd;
	for(int j = 0; j < MAP_SIZE_HEIGHT ; j ++)
	{
		for(int i = 1; i < MAP_SIZE_WIDTH ; i ++)
		{
			delete map[i][j];
		}
	}
}